<template>
	<view class="container">
		<block>

			<view style="width:100%;height: 100%;">
				<view class="bg_div1" style="background: #d9e0f2;">
					<view style="overflow: hidden;">
						<view class="logo2">

							<image src="/static/tabbar/my-h.png" style="width: 100%;height: 100%;" mode=""></image>
						</view>

						<view class="content_div1">
							<view>
								<view class="card_div1" style="background:#fff">

									<view>
										<view class="title1"
											style="color: #000000;text-align: center;margin-top: 10px;font-size: 20px;">
											登录
										</view>

									</view>

									<view class="tel1">
										<input type="text" name="tel" value="" @input="telinput" class="input_val"
											placeholder="请输入手机号码"
											placeholder-style="color:#CACACA;line-height: 100rpx;" />
									</view>
									<!-- <view v-if="logintype==1" class="tel1">
										<input type="text" name="pwd" value="" :password="true" placeholder="请输入密码"
											placeholder-style="color:#CACACA;line-height: 100rpx;" class="input_val" />
									</view> -->

									<view class="tel1">
										<input type="text" name="smscode" v-model="smscodes" value=""
											placeholder="请输入验证码" placeholder-style="color:#CACACA;line-height: 100rpx;"
											class="inputcode" />
										<text class="code1" style="color: #0256FF"
											@tap="smscode">{{smsdjs||'获取验证码'}}</text>
									</view>

									<view style="margin-top: 40rpx;">

										<button class="btn1" open-type="getPhoneNumber" @getphonenumber="sdlogin"
											form-type="submit" style="background: rgba(51,136,255);
    color: #FFFFFF;">登录</button>
									</view>

									<!-- 设置头像昵称e -->
									<button open-type="getPhoneNumber" @getphonenumber="getPhoneNumber" class="btn1"
										style="background:#00dd83;color: #fff">手机号一键登录</button>

								</view>
							</view>
						</view>

					</view>
					<!-- e -->
				</view>

			</view>

		</block>

	</view>
</template>

<script>
	var app = getApp();
  import {loginfoin, logwechatusersendMsg,} from '../../utils/new_file.js'
  // import {
	// 	mapState,
	// 	mapMutations
	// } from 'vuex'
	export default {
		data() {
			return {
				tel: '',//手机号
				hqing: 0,
				geturl: '',
				smsdjs: '',//验证码倒计时
				smscodes: '',//密码
				verCode: ''//验证码
			};
		},
		onLoad(ope) {
			this.geturl = ope.geturl
		},
		methods: {
			// ...mapMutations(['loguserId']), //引入store方法
			getPhoneNumber(res) {
				let what = this
				app.showLoading('正在登陆')
				uni.login({
					 success(res2) {
						let obj = {
							code: res2.code,
							appId: app.globalData.appId,
							appSecret: app.globalData.appSecret,
							phoneCode: res.detail.code
						}
             console.log('getPhoneNumber', res2);
						 loginfoin(obj).then(data=>{
               if (data.data.code == 200) {
                 app.success('登录成功', function () {
                   uni.setStorageSync('useinfo', data.data.data)
                   // let putdata =
                   // 	await putwxuserwechatuser(uni.getStorageSync('useinfo'))
                   // what.loguserId(data.data.userId)
                   // 返回登录之前的页面
                   // uni.navigateBack()
                   console.log(what.geturl);
                   setTimeout(() => {
                     if (what.geturl == "pages/order/order" || what.geturl ==
                         "pages/my/my") {
                       console.log('yes');
                       what.geturl = '/' + what.geturl
                       uni.switchTab({
                         url: what.geturl
                       })
                     } else {
                       uni.navigateBack()
                       // what.geturl='/'+what.geturl
                       // uni.reLaunch({
                       // 	url:what.geturl
                       // })
                     }
                   }, 2000);
							})
               }
						})
					}
				})
			},
			telinput: function(e) {
				this.tel = e.detail.value
			},
			smscode:  function() {
				var that = this;
				if (that.hqing == 1) return;
				that.hqing = 1;
				var tel = that.tel;
				if (tel == '') {
					app.alert('请输入手机号码');
					that.hqing = 0;
					return false;
				}
				if (!/^1[3456789]\d{9}$/.test(tel)) {
					app.alert("手机号码有误，请重填");
					that.hqing = 0;
					return false;
				}
				logwechatusersendMsg(tel).then(data => {
					console.log(data);
					this.verCode = data.data.verCode
					// app.post("ApiIndex/sendsms", {
					// 	tel: tel
					// }, function(data) {
					// 	if (data.status != 1) {
					// 		app.alert(data.msg);
					// 		return;
					// 	}
					// });
					var time = 120;
					var interval1 = setInterval(function() {
						time--;
						if (time < 0) {
							that.smsdjs = '重新获取';
							that.hqing = 0;
							clearInterval(interval1);
						} else if (time >= 0) {
							that.smsdjs = time + '秒';
						}
					}, 1000);
				})

			},
			sdlogin(res) {
				let what = this
				app.showLoading('正在登陆')
				if (what.verCode == what.smscodes) {
					uni.login({
						success(res2) {
							let obj = {
								code: res2.code,
								appId: app.globalData.appId,
								appSecret: app.globalData.appSecret,
								phoneCode: res.detail.code
							}

							loginfoin(obj).then(data => {
								if (data.data.code == 200) {
									app.success('登录成功', function() {
										uni.setStorageSync('useinfo', data.data.data)
										// 返回登录之前的页面
										// uni.navigateBack()
										console.log(what.geturl);
										setTimeout(() => {
											if (what.geturl == "pages/order/order" || what
												.geturl == "pages/my/my") {
												console.log('yes');
												what.geturl = '/' + what.geturl
												uni.switchTab({
													url: what.geturl
												})
											} else {
												uni.navigateBack()
												// what.geturl='/'+what.geturl
												// uni.reLaunch({
												// 	url:what.geturl
												// })
											}
										}, 1000);
									})
								}
							})

						}
					})

				} else {
					app.alert('验证码错误');
				}
			}
		}
	}
</script>

<style>
	page {
		background: #ffffff;
		width: 100%;
		height: 100%;
	}

	.container {
		width: 100%;
		height: 100%;
	}

	.text-center {
		text-align: center;
	}

	.title {
		margin: 70rpx 50rpx 50rpx 40rpx;
		height: 60rpx;
		line-height: 60rpx;
		font-size: 48rpx;
		font-weight: bold;
		color: #000000;
	}

	.loginform {
		width: 100%;
		padding: 0 50rpx;
		border-radius: 5px;
		background: #FFF;
	}

	.loginform .form-item {
		display: flex;
		align-items: center;
		width: 100%;
		border-bottom: 1px #ededed solid;
		height: 88rpx;
		line-height: 88rpx;
		border-bottom: 1px solid #F0F3F6;
		margin-top: 20rpx
	}

	.loginform .form-item .img {
		width: 44rpx;
		height: 44rpx;
		margin-right: 30rpx
	}

	.loginform .form-item .input {
		flex: 1;
		color: #000;
		background: none;
	}

	.loginform .form-item .code {
		font-size: 30rpx
	}

	.xieyi-item {
		display: flex;
		align-items: center;
		margin-top: 30rpx
	}

	.xieyi-item {
		font-size: 24rpx;
		color: #B2B5BE
	}

	.xieyi-item .checkbox {
		transform: scale(0.6);
	}

	.authlogin {
		display: flex;
		flex-direction: column;
		align-items: center
	}

	.authlogin-logo {
		width: 180rpx;
		height: 180rpx;
		margin-top: 120rpx
	}

	.authlogin-name {
		color: #999999;
		font-size: 30rpx;
		margin-top: 60rpx;
	}

	.authlogin-btn {
		width: 580rpx;
		height: 96rpx;
		line-height: 96rpx;
		background: #51B1F5;
		border-radius: 48rpx;
		color: #fff;
		margin-top: 100rpx
	}

	.authlogin-btn2 {
		width: 580rpx;
		height: 96rpx;
		line-height: 96rpx;
		background: #EEEEEE;
		border-radius: 48rpx;
		color: #A9A9A9;
		margin-top: 20rpx
	}

	.ioslogin-btn {
		width: 580rpx;
		height: 96rpx;
		line-height: 96rpx;
		background: #fff;
		border-radius: 48rpx;
		color: #fff;
		border: 1px solid #555;
		color: #333;
		font-weight: bold;
		margin-top: 30rpx;
		font-size: 30rpx;
		display: flex;
		justify-content: center;
		align-items: center
	}

	.ioslogin-btn image {
		width: 26rpx;
		height: 26rpx;
		margin-right: 16rpx;
	}

	.googlelogin-btn {
		width: 580rpx;
		height: 96rpx;
		line-height: 96rpx;
		background: #fff;
		border-radius: 48rpx;
		color: #fff;
		border: 1px solid #555;
		color: #333;
		font-weight: bold;
		margin-top: 30rpx;
		font-size: 30rpx;
		display: flex;
		justify-content: center;
		align-items: center
	}

	.googlelogin-btn2 {
		margin-top: 30rpx;
		display: flex;
		justify-content: center;
		align-items: center
	}

	.xieyibox {
		width: 100%;
		height: 100%;
		position: fixed;
		top: 0;
		left: 0;
		z-index: 99;
		background: rgba(0, 0, 0, 0.7)
	}

	.xieyibox-content {
		width: 90%;
		margin: 0 auto;
		/*  #ifdef  MP-TOUTIAO */
		height: 60%;
		/*  #endif  */
		/*  #ifndef  MP-TOUTIAO */
		height: 80%;
		/*  #endif  */
		margin-top: 20%;
		background: #fff;
		color: #333;
		padding: 5px 10px 50px 10px;
		position: relative;
		border-radius: 2px;
	}

	.bg_div1 {
		width: 100%;
		min-height: 100%;
		overflow: hidden;
	}

	.content_div1 {
		width: 700rpx;
		margin: 0 auto;
		margin-bottom: 60rpx;
	}

	.title1 {
		opacity: 1;
		font-size: 50rpx;
		font-weight: bold;
		line-height: 90rpx;
		text-align: left;
		margin-top: 80rpx;
	}

	.subhead1 {
		font-size: 28rpx;
		font-weight: 500;
		line-height: 40rpx;
	}

	.card_div1 {
		width: 100%;
		padding: 40rpx;
		border-radius: 24rpx;
		margin-top: 40rpx;
	}

	.tel1 {
		width: 100%;
		height: 100rpx;
		border-radius: 100rpx;
		line-height: 100rpx;
		background-color: #F5F7FA;
		padding: 0 40rpx;
		margin: 20rpx 0;
		margin-top: 30rpx;
	}

	.code1 {
		height: 100rpx;
		font-size: 24rpx;
		line-height: 100rpx;
		float: right;
	}

	.btn1 {
		width: 100%;
		height: 100rpx;
		border-radius: 100rpx;
		line-height: 100rpx;
		margin: 20rpx 0;
		text-align: center;
		font-weight: bold;
		color: #A9A9A9;
		font-size: 30rpx
	}

	.other_line {
		width: 106rpx;
		height: 2rpx;
		background: #D8D8D8;
		margin-top: 20rpx;
	}

	.logo2 {
		width: 200rpx;
		height: 200rpx;
		margin: 0 auto;
		margin-top: 40rpx;
		margin-bottom: 40rpx;
		border-radius: 12rpx;
		overflow: hidden;
	}

	.inputcode {
		width: 300rpx;
		height: 100rpx;
		line-height: 100rpx;
		display: inline-block;
		background: none;
	}

	.input_val {
		width: 100%;
		height: 100rpx;
		line-height: 100rpx;
		background: none;
	}

	.xycss1 {
		line-height: 60rpx;
		font-size: 24rpx;
		overflow: hidden;
	}

	.other_login {
		width: 420rpx;
		margin: 60rpx auto;
	}

	.overflow_ellipsis {
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
		width: 380rpx;
	}

	.other_content {
		overflow: hidden;
		width: 100%;
		margin-top: 60rpx;
		text-align: center;
		display: flex;
		justify-content: center;
	}
</style>